stage.set_background("city")
sprite = codesters.Sprite("bike")
sprite.set_size(0.5)
sprite.go_to(-200, 0)
stage.set_gravity(10)
stage.disable_all_walls()
def space_bar():
sprite.jump(5)
# add other actions...
stage.event_key("space", space_bar)
def interval():
# add any other actions...
top_height = random.randint(50, 300)
# sprite = codesters.Rectangle(x, y, width, height, "color")
top_block = codesters.Rectangle(0, 0, 100, top_height, "blue")
top_block.set_gravity_off()
top_block.set_top(250)
bot_height = 350 - top_height
stage.event_interval(interval, 2)
t = codesters.Teacher()
try:
params = t.find_function("Rectangle")
tval1 = t.get_indent_at_line(params[1][0])
tval2 = params[1][1]
except:
tval1 = "DNE"
tval2 = "DNE"
try:
params = t.find_text("bot_block")
tval3 = t.get_indent_at_line(params[0][0])
tval4 = params[0][1]
except:
params = "DNE"
tval3 = "DNE"
tval4 = "DNE"
try:
params = t.get_parameters_for_function('Rectangle')
tval6 = params[1][3]
except:
params = "DNE"
tval5 = "DNE"
tval6 = "DNE"
#print(tval1)
tester = TestManager()
t1 = TestObjective()
t1.add_success(tval1 == 4 and "codesters.Rectangle" in tval2, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add another rectangle?")
t1.add_failure(tval1 == 0, "Your rectangle should be indented four spaces inside the interval event")
t2 = TestObjective()
t2.add_success(tval4 != "DNE" and tval3 == 4, "Great job!")
t2.add_failure(tval4 == "DNE" or params == [], "Did you change the name of your rectangle?")
t2.add_failure(tval3 != 4, "Did you unindent your rectangle? It needs to be indented four spaces.")
t3 = TestObjective()
t3.add_success(tval6 == "bot_height", "Great job!")
t3.add_failure(tval6 == 50, "Did you change the rectangle's height to bot_height?")
t3.add_failure(tval6 != "bot_height", "Did you use the variable bot_height for the rectangle's height?")
# print params
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
# print params
# print tval2, tval1
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)